package groupb6.shopsystem.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import groupb6.shopsystem.mapper.UserMapper;
import groupb6.shopsystem.pojo.entity.Order;
import groupb6.shopsystem.pojo.entity.User;
import groupb6.shopsystem.util.enums.IdentityEnum;
import groupb6.shopsystem.util.response.UniversalResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@Api(tags = "99:聊天相关")
@ApiSupport(author = "zhangyn")
@RestController
@RequestMapping("/websocket")
public class WebsocketController {
    @Autowired
    UserMapper userMapper;
    //TODO:完成用http协议实现的相关功能（暂时没想到需要什么相关功能）
    /**
     * 获取全部用户id
     * @return
     */
    @ApiOperation("获取买家id")
    @PostMapping("/ids")
    @ResponseBody
    public UniversalResponse<List<Integer>> getIds() {
        QueryWrapper<User> wrapper=new QueryWrapper<>();
        wrapper.eq("identity", IdentityEnum.BUYER.getIdentity());
        return new UniversalResponse<>(1000,"sucess",userMapper.selectList(wrapper).stream().map(User::getId).collect(Collectors.toList())) ;
    }
    /**
     * 获取全部买家id
     */
    @ApiOperation("获取全部卖家id")
    @PostMapping("/ids1")
    @ResponseBody
    public UniversalResponse<List<Integer>> getCusIds() {
        QueryWrapper<User> wrapper=new QueryWrapper<>();
        wrapper.eq("identity", IdentityEnum.SELLER.getIdentity());
        return new UniversalResponse<>(1000,"sucess",userMapper.selectList(wrapper).stream().map(User::getId).collect(Collectors.toList())) ;
    }
}
